package at.pp.match3.game.assets;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import at.pp.match3.core.LOG;
import at.pp.match3.game.render.GameAsset;

public class TileAsset extends GameAsset {

    private static final long STROKE_WIDTH = 2L;
    private Paint paint;

    public TileAsset(final int positionX, final int positionY, final Bitmap bitmap) {
        super(positionX, positionY, bitmap);
        selectionRect = new Rect(positionX, positionY, positionX
                + bitmap.getWidth(), positionY + bitmap.getHeight());
        LOG.log(selectionRect.toString());
        paint = new Paint();
        paint.setStrokeWidth(STROKE_WIDTH);
        paint.setColor(Color.RED);

        setSelecatable(true);
    }

    @Override
    public final void render(final Canvas canvas) {
        if (isSelected) {
            canvas.drawRect(selectionRect, paint);
        }
        canvas.drawBitmap(bitmap, positionX, positionY, null);
    }

    @Override
    public void update(final long deltaTime) {
    }

    @Override
    public void select(final boolean select) {
        // select an unselected element
        if (!isSelected && select) {
            originalBitmap = bitmap;
            bitmap = selectedBitmap;
            setSelected(true);
            // deselect a selected element
        } else if (isSelected() && !select) {
            bitmap = originalBitmap;
            setSelected(false);
        }
    }
}
